package com.vhall.component.entity.chat.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.vhall.component.framework.common.utils.CollectionUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author guoxin.wang
 * @date 2021/5/31 10:30
 */
@Data
public class ReservationConsoleListPage<T extends Serializable> implements Serializable {

    private static final long serialVersionUID = -4171701556169696633L;

    @JsonProperty(value = "from")
    private Integer from;

    @JsonProperty(value = "to")
    private Integer to;

    @JsonProperty(value = "total")
    private Integer total;

    @JsonProperty(value = "page_num")
    private Integer pageNum;

    @JsonProperty(value = "page_all")
    private Integer pageAll;

    @JsonProperty(value = "per_page")
    private Integer perPage;

    @JsonProperty(value = "list")
    private List<T> list;

    public ReservationConsoleListPage(Integer index, int size, int total, List<T> list) {
        this.pageNum = index;
        this.total = total;
        this.perPage = size;
        this.list = list;
        this.from = CollectionUtils.isNotEmpty(list) ? (index - 1) * (size + 1) : 0;
        this.to = CollectionUtils.isNotEmpty(list) ? this.from + (list.size() - 1) : 0;
        this.pageAll = Math.max((int) Math.ceil(total / (double) size), 1);
    }

}
